package com.example.myapp.webView.ui;

import com.example.myapp.MainActivity;
import com.example.myapp.R;
import com.example.myapp.fragment.HomeActivity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class WebViewToHtmlActivity extends Activity {
	WebView webView_toHtml;
	private String url;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_webviewtohtml);
		url = "file:///android_asset/guide/index.html";
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		webView_toHtml = (WebView) findViewById(R.id.webView_toHtml);
		loadLocalHtml();
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void loadLocalHtml() {
		// TODO Auto-generated method stub
		WebSettings webSettings = webView_toHtml.getSettings();
		webSettings.setSupportZoom(true);//手势控制放大缩小
		webSettings.setBuiltInZoomControls(true);//必须加载，不然手势不起作用
		webSettings.setDisplayZoomControls(false);//隐藏控制条
		webSettings.setJavaScriptEnabled(true);//开启JavaScript支持
		webView_toHtml.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// TODO Auto-generated method stub
				// 重写此方法，用于捕捉页面上的跳转链接
				if ("http://start/".equals(url)) {
					// 在html代码中的按钮跳转地址需要同此地址一致
					Toast.makeText(WebViewToHtmlActivity.this, "开始体验", Toast.LENGTH_SHORT).show();
				}
				return true;
			}
		});
		webView_toHtml.loadUrl(url);
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(WebViewToHtmlActivity.this, HomeActivity.class);
		startActivity(intent);
		finish();

	}
}
